Skip to content

feat(api): support v2 namespace endpoints in @supabase/api - #6142

Merged
Coly010 merged 7 commits into
developfrom
columferry/cli-2157-support-v2-namespace-endpoints-in-supabaseapi
Aug 11, 2026
Merged

feat(api): support v2 namespace endpoints in @supabase/api#6142
Coly010 merged 7 commits into
developfrom
columferry/cli-2157-support-v2-namespace-endpoints-in-supabaseapi

Conversation

@Coly010

@Coly010 Coly010 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

What changed

`@supabase/api` previously modeled only the Management API v1 namespace. The upstream API publishes two OpenAPI documents (`/api/v1-json` and `/api/v2-json`), and the config endpoint needed by CLI-2156/CLI-2064 lives on v2. This PR makes v2 a first-class namespace:

  • `scripts/download-openapi.ts` fetches both documents from the same base URL, merges them (paths + `components.schemas` unioned with collision asserts; `info.title` normalized), applies overrides to the merged document, and validates operationId uniqueness and version/path agreement. A missing v2 document is a hard failure — tolerating it would silently delete the namespace and the hourly sync would auto-merge the deletion.
  • `scripts/generate.ts` derives the client namespace from the path's leading segment (`/v2/...` → `api.v2.*`) instead of the operationId prefix, with a hard error on duplicate `(version, method)` pairs. Adding a v3 later requires no generator changes. All 170 existing v1 operations produce byte-identical output — the regenerated `contracts.ts`/`effect-client.ts` diff is additions-only (verified: zero removed lines).
  • `scripts/openapi-overrides.json` gains a tolerant `remove` op (remove-if-present, a documented RFC 6902 deviation) and 13 entries removing the v2 webhook paths + `APIErrorObject`. Upstream spec bug (still present in prod): all 10 project-webhook operations share one operationId (`allV2ProjectsByRefWebhooks`), the 10 org-webhook ones share another — duplicated and not version-prefixed, which breaks codegen.
  • `scripts/openapi-source.json` (new, committed) pins the spec source base URL — `https://api.supabase.com\` — so `pnpm generate` reproduces the snapshot with no env var and provenance is visible in diffs. `SUPABASE_API_URL` still overrides it (e.g. for staging).
  • Drift detection: `src/generated-contract-sync.unit.test.ts` asserts a full bijection between the committed snapshot and the generated modules in ordinary PR CI (this is what catches a hand-edited snapshot or client — the failure mode from the feat(cli): add config pull command #6111 POC). `pnpm generate:check` mirrors the hourly sync's regenerate→format→diff sequence for live verification.
  • `api-package-sync.yml` is pinned to `https://api.supabase.com\` so develop's hourly sync always regenerates from prod regardless of the sidecar.

The proving case, `GET /v2/projects/{ref}/config` → `api.v2.getProjectConfig` (typed `V2ProjectConfigResponse`), was staging-only when this branch started; it shipped to production on 2026-08-11 with a byte-identical definition, the snapshot regenerates from prod exactly, and the source pin now points at prod. No merge gate remains.

Known limitation

Three v2 operations (`v2-list-organization-members`, `v2-list-organization-projects`, `v2-list-organization-github-connections`) declare `style: deepObject` object query params, which the client currently serializes as JSON strings rather than `page[size]=...`. Documented in the README; the typed surface is correct, the wire format for those params is not.

Part of CLI-2157 (unblocks CLI-2156 and CLI-2064).

Fetch and merge both Management API OpenAPI documents (/api/v1-json and
/api/v2-json), derive client namespaces from the path, and regenerate the
snapshot so v2 operations are callable as api.v2.<operation>.

- download-openapi.ts: two-document fetch (hard-fail on a missing doc),
  structural merge with collision asserts, tolerant remove override op,
  committed source pin in scripts/openapi-source.json (staging for now:
  GET /v2/projects/{ref}/config has not shipped to prod yet)
- generate.ts: version namespace derived from the leading path segment,
  duplicate-operation hard error; v1 output is byte-identical
- openapi-overrides.json: remove the v2 webhook paths (upstream spec bug:
  duplicated, non-version-prefixed operationIds) and APIErrorObject
- api-package-sync.yml: pin hourly sync to prod, diff the source pin
- generate:check script + README spec-pipeline/override/merge-gate docs
- generated-contract-sync.unit.test.ts: bijection between the committed
  openapi.json snapshot and the generated contracts/effect client, so a
  hand-edited snapshot or client fails CI
- client.unit.test.ts: 404 on a v2 operation surfaces as a StatusCodeError
  with the response status; v2 requests carry identical auth/base-url
  wiring; nested V2ProjectConfigResponse payload decodes strictly
- effect.unit.test.ts: same-named v1/v2 operations are separately
  addressable per namespace
- export OpenApiDocument/OpenApiOperation types from generate.ts for
  typed test fixtures
ApiClient now carries a v2 namespace, so the v1-only mock object no
longer overlaps the ApiClient type. The legacy shell only calls v1
operations; v2 calls die loudly as wiring bugs.
GET /v2/projects/{ref}/config shipped to production (byte-identical to
the staging definition the snapshot was generated from), so regenerating
from prod reproduces the committed snapshot exactly — only the source
pin changes. Drops the temporary staging warnings.
@Coly010
Coly010 marked this pull request as ready for review August 11, 2026 10:25
@Coly010
Coly010 requested a review from a team as a code owner August 11, 2026 10:25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 969c85e9b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/api/package.json Outdated
Comment thread packages/api/scripts/download-openapi.ts Outdated
@github-actions

github-actions Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Supabase CLI preview

npx --yes https://pkg.pr.new/supabase/cli/supabase@e57345649f794f1f727f333aa17703e200b8fffd

Preview package for commit e573456.

…ource-pin precedence

Review follow-ups on #6142:

- New generated-output-sync test re-renders contracts.ts, effect-client.ts
  and openapi.json from the committed snapshot through the same oxfmt the
  pipeline uses and requires byte equality, so hand edits to schemas,
  parameters, request bodies, response types, or the executor fail plain
  PR CI (the prior bijection test only covered operation-level identity)
- mergeOpenApiDocuments now emits only the keys the generator consumes;
  upstream servers/tags/securitySchemes no longer appear even in the
  intermediate write between generate:spec and generate.ts, which is the
  state that presented as snapshot drift during review
- SUPABASE_API_URL now takes precedence without reading the source pin,
  and a missing pin falls through to the default instead of throwing
- generate:check invokes pnpm generate rather than bun run generate
Bun on Linux truncates a child process's piped stdout at ~219KB, so the
stdin/stdout round-trip through oxfmt cut the 600KB+ renders mid-line on
CI while passing on macOS. File mode writes and reads through the
filesystem — no pipe — and is also what the pipeline's fmt:fix runs, which
drops the stdin-mode trailing-newline normalization too.
@Coly010
Coly010 added this pull request to the merge queue Aug 11, 2026
Merged via the queue into develop with commit af1ed9a Aug 11, 2026
14 checks passed
@Coly010
Coly010 deleted the columferry/cli-2157-support-v2-namespace-endpoints-in-supabaseapi branch August 11, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants